package com.sky.wsp.spring.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.Locale;

/**
 * @desccription 在此输入描述
 * @auth wangshaopeng@talkweb.com.cn
 * @date 2023/4/4
 */
@RestController
public class IndexController {

    @GetMapping()
    public String index(HttpServletRequest request){
        System.out.println("============================headers============================");
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()){
            String name = headerNames.nextElement();
            String header = request.getHeader(name);
            System.out.println(name + ": " + header);
        }
//        System.out.println("============================attributes============================");
//        Enumeration<String> attributeNames = request.getAttributeNames();
//        while (attributeNames.hasMoreElements()){
//            String name = attributeNames.nextElement();
//            Object attribute = request.getAttribute(name);
//            System.out.println(name + ": " + attribute);
//        }
        System.out.println("============================locales============================");
        Enumeration<Locale> locales = request.getLocales();
        while (locales.hasMoreElements()){
            Locale locale = locales.nextElement();
            System.out.println(locale.getDisplayName() + ": " + locale.getLanguage());
        }
        String scheme = request.getScheme();
        String serverName = request.getServerName();
        int serverPort = request.getServerPort();
        String contextPath = request.getContextPath();
        String localAddr = request.getLocalAddr();
        return "====> " + localAddr + "的首页：" + scheme + "://" + serverName + ":" + serverPort + contextPath + "\n";
    }
}
